home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / D-G / DropInfo ƒ / DI⁄P / DropShell.p < prev    next >
Encoding:
Text File  |  1991-12-11  |  6.2 KB  |  251 lines  |  [TEXT/MPS ]

  1. {******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DropShell.p
  5. **
  6. **   Description:    Main application code for the DropShell
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **
  16. *******************************************************************************
  17. **                      R E V I S I O N   H I S T O R Y
  18. *******************************************************************************
  19. **
  20. **      Date        Time    Author    Description
  21. **    --------    -----    ------    ---------------------------------------------
  22. **    12/09/91            LDR        Added support for new "Select File…" menu item
  23. **                                Quit now sends AEVT to self to be politically correct
  24. **                                Added support for the new gSplashScreen
  25. **    11/24/91            LDR        Added support for the Apple Menu (duh!)
  26. **                                Moved CenterAlert & ErrorAlert to DSUtils
  27. **    10/30/91            LDR        Modified USES clause for new include & ifc'ed ThP
  28. **    10/28/91            LDR        Officially renamed DropShell (from QuickShell)
  29. **                                Added a bunch of comments for clarification
  30. **    04/09/91    00:02    LDR        Original Version
  31. **
  32. ******************************************************************************}
  33.  
  34. PROGRAM DropShell;
  35.  
  36. {$IFC THINK_Pascal}
  37.     USES
  38.         Script, DSGlobals, DSUtils, DSUserProcs, DSAppleEvents;    {just the DropShell files}
  39. {$ELSEC}
  40.     USES
  41.     { First load standard interface files}
  42.         MemTypes, QuickDraw, 
  43.  
  44.     { Now include the stuff from OSIntf }
  45.         OSIntf, 
  46.  
  47.     { Now Include the stuff from ToolIntf.p }
  48.         ToolIntf, Packages, GestaltEqu, 
  49.  
  50.     { Then any OTHER Toolbox interfaces... }
  51.         Files, Aliases, AppleEvents,
  52.  
  53.     { And finally any files from DropShell }
  54.         DSGlobals, DSUtils, DSUserProcs, DSAppleEvents;
  55. {$ENDC THINK_Pascal}
  56.  
  57. {CODE BEGINS HERE}
  58.  
  59. {$IFC THINK_Pascal}
  60. {$ELSEC}
  61.     {
  62.         This routine is automatically linked in by the MPW Linker. 
  63.         This external reference to it is done so that we can unload its segment, %A5Init.
  64.     }
  65.     PROCEDURE _DataInit; EXTERNAL;
  66. {$ENDC THINK_Pascal}
  67.  
  68.     {Simple routine installed by InitDialogs for the Resume button in Bomb boxes}
  69.     PROCEDURE Panic;
  70.     BEGIN
  71.         ExitToShell;
  72.     END;
  73.  
  74.     {$S Initialize}
  75.     {Nothing special here, just initting the toolbox}
  76.     PROCEDURE InitToolbox;
  77.     BEGIN
  78. {$IFC THINK_Pascal}
  79. {$ELSEC}
  80.         UnloadSeg(@_DataInit);    {we love you MPW!}
  81. {$ENDC THINK_Pascal}
  82.  
  83.         InitGraf(@thePort);
  84.         InitFonts;
  85.         InitWindows;
  86.         InitMenus;
  87.         TEInit;
  88.         InitDialogs(@Panic);
  89.         InitCursor;
  90.         FlushEvents(everyEvent, 0);
  91.         
  92.         {how about some memory fun!}
  93.         MoreMasters;
  94.         MoreMasters;    {two should be enough!}
  95.     END;
  96.     
  97.     {
  98.         Let's setup those global variables that the DropShell uses.
  99.         
  100.         If you add any globals for your own use,
  101.         init them in the InitUserGlobals routine in DSUserProcs.c
  102.     }
  103.     FUNCTION InitGlobals: Boolean;
  104.     VAR
  105.         aLong: longint;
  106.     BEGIN
  107.         gDone := FALSE;
  108.         gOApped := FALSE;    {Assume it wasn't, since most users wont!}
  109.         gHasAppleEvents := (Gestalt(gestaltAppleEventsAttr, aLong) = noErr);
  110.         gSplashScreen := NIL;
  111.         
  112.         InitGlobals := InitUserGlobals;    {call the user proc}
  113.     END;
  114.     
  115.     {
  116.         Again, nothing fancy.  Just setting up the menus.
  117.         
  118.         If you add any menus to your DropBox - insert them here!
  119.     }
  120.     PROCEDURE SetUpMenus;
  121.     BEGIN
  122.         gAppleMenu := GetMenu(kAppleNum);
  123.         AddResMenu(gAppleMenu, 'DRVR');
  124.         InsertMenu(gAppleMenu, 0);
  125.  
  126.         gFileMenu := GetMenu(kFileNum);
  127.         InsertMenu(gFileMenu, 0);
  128.         DrawMenuBar;
  129.     END;
  130.     
  131.     {
  132.         This routine is called during startup to display a splash screen.
  133.         
  134.         This was recommend by the Blue Team HI person, John Sullivan, who
  135.         feels that all apps should display something so that users can easily
  136.         tell what is running, and be able to switch by clicking.  Thanks John!
  137.     }
  138.     PROCEDURE InstallSplashScreen;
  139.     CONST
  140.         windowPicID = 128;
  141.     VAR
  142.         picH: PicHandle;
  143.     BEGIN
  144.         IF (gSplashScreen = NIL) THEN { show the splash screen window }
  145.         BEGIN
  146.             picH := GetPicture(windowPicID);
  147.             IF picH <> NIL THEN
  148.             BEGIN
  149.                 gSplashScreen := GetNewWindow(windowPicID, NIL, Pointer(-1));
  150.                 IF gSplashScreen <> NIL THEN
  151.                 BEGIN
  152.                     SetWindowPic(gSplashScreen, picH);
  153.                     ShowWindow(gSplashScreen);
  154.                 END;
  155.             END;
  156.         END;
  157.     END;
  158.  
  159. {$S Main}
  160.  
  161. {** Standard Event Handling routines **}
  162.     PROCEDURE ShowAbout;
  163.     VAR
  164.         itemHit: integer;
  165.     BEGIN
  166.         itemHit := Alert(128, NIL);
  167.     END;
  168.     
  169.     PROCEDURE DoMenu(retVal: longint);
  170.     VAR
  171.         menuID, itemID: integer;
  172.         itemStr: Str255;
  173.         refNum: integer;
  174.     BEGIN
  175.         menuID := HiWord(retVal);
  176.         itemID := LoWord(retVal);
  177.         
  178.         CASE menuID OF
  179.             kAppleNum:
  180.                 IF itemID = 1 THEN    {handle the about box}
  181.                     ShowAbout    
  182.                 ELSE                {get the DA's}
  183.                 BEGIN
  184.                     GetItem(GetMHandle(kAppleNum), itemID, itemStr);
  185.                     refNum := OpenDeskAcc(itemStr);
  186.                 END;
  187.             kFileNum:
  188.                 IF itemID = 1 THEN    {Select File…}
  189.                     SelectFile
  190.                 ELSE
  191.                     SendQuitToSelf;    {send me a quit event}
  192.         END;
  193.         HiliteMenu(0);        {turn it off}
  194.     END;
  195.     
  196.     PROCEDURE DoMouseDown(curEvent:EventRecord);
  197.     VAR
  198.         whichWindow:    WindowPtr;
  199.         whichPart:        integer;
  200.     BEGIN
  201.         whichPart := FindWindow (curEvent.where, whichWindow);
  202.         case whichPart of
  203.             inMenuBar:        DoMenu (MenuSelect (curEvent.where));
  204.             inSysWindow:    SystemClick (curEvent, whichWindow);
  205.             inDrag:            DragWindow(whichWindow, curEvent.where, screenBits.bounds);
  206.             inDesk, inContent, inGrow, inGoAway, inZoomIn, inZoomOut:
  207.                     {Do nothing};
  208.         end; {case}
  209.     END; {DoMouseDown}
  210.     
  211.     PROCEDURE DoKeyDown(curEvent:EventRecord);
  212.     VAR
  213.         ch:                char;
  214.     BEGIN
  215.         ch := CHR(BitAnd (curEvent.message, charCodeMask));
  216.         
  217.         IF BitAnd (curEvent.modifiers, cmdKey) <> 0 THEN
  218.             DoMenu (MenuKey (ch));
  219.     END; {DoKeyDown}
  220.  
  221. {Main Program Starts Here}
  222. BEGIN
  223.     InitToolbox;
  224.     IF (InitGlobals) THEN
  225.     BEGIN
  226.         IF gHasAppleEvents THEN
  227.         BEGIN
  228.             InitAEVTStuff;
  229.             SetupMenus;
  230.             InstallSplashScreen;
  231.             
  232.             WHILE NOT gDone DO
  233.             BEGIN
  234.                 gWasEvent := WaitNextEvent(everyEvent, gEvent, 0, NIL);
  235.                 IF gWasEvent THEN
  236.                 BEGIN
  237.                     CASE gEvent.what OF
  238.                         kHighLevelEvent:    DoHighLevelEvent(gEvent);
  239.                         mouseDown:            DoMouseDown(gEvent);
  240.                         keyDown, autoKey:    DoKeyDown(gEvent);
  241.                         OTHERWISE
  242.                                 {Do nothing}
  243.                     END; {case}
  244.                 END;
  245.             END;    
  246.         END
  247.         ELSE
  248.             ErrorAlert(kErrStringID, kCantRunErr, 0);
  249.     END;
  250. END.
  251.